const { validationResult } = require("express-validator");

exports.validate = (rules) => {
  return async (req, res, next) => {
    await Promise.all(rules.map((rule) => rule.run(req)));
    const errors = validationResult(req);
    if (!errors.isEmpty()) {
      return res.send(errors);
    } else {
      next();
    }
  };
};
